/** @file DomBuilder.h
    @brief The DomBuilder class is responsible for creating the domain object 
	model from a configuration file. It can be thought of as a factory, to which
	you give a file path of a configuration and returns to you the DOM. It relies
	on the TinyXML parser library to intially parse the file. The created DOM 
	consists of the classes defined in Sa2dDom.h.

    @author Andri Lareida
    
    @date 28. January, 2010
    
*/

#ifndef DOMBUILDER_H_
#define DOMBUILDER_H_

#include <tinyxml.h>
#include "Sa2dDom.h"


class DomBuilder {

private:

	paramSet * defaultAI;
    configurationfile* configModel;
	
	/**
	  *Method to split the creation of the DOM
	  */
	void fillSimulation(TiXmlElement* simElement);
	
	/**
	  *Method to split the creation of the DOM
	  */
    void fillPhysicsEngine(TiXmlElement *simElement);
	
	/**
	  *Method to split the creation of the DOM
	  */
    void fillPerformer(TiXmlElement *performerElement);
	
	/**
	  *Method to split the creation of the DOM
	  */
    void fillWindowSettings(TiXmlElement *window);
	
	/**
	  *Method to split the creation of the DOM
	  */
    void fillArena(TiXmlElement *arenaElement);
	
	/**
	  *Method to split the creation of the DOM
	  */
    void fillAgents(TiXmlElement *agentElement);

	 /**
      * Creates an arena shape object from the given TiXMLElement.
      * @param shapeElement this is the XML element representing an arena shape.
      * @return a shape object, with the values of the provided element.
      */
    shape *createArenaShape(TiXmlElement *shapeElement);
	
	 /**
      * Creates a position object from the given TiXMLElement.
      * @param shapeElement this is the XML element representing a position.
      * @return a position object, with the values of the provided element.
      */
    position *createPosition(TiXmlElement *shapeElement);
	
	 /**
      * Creates a rotation object from the given TiXMLElement.
      * @param rotationElement this is the XML element representing a rotation.
      * @return a rotation object, with the values of the provided element.
      */
    rotation *createRotation(TiXmlElement *rotationElement);
	
	 /**
      * Creates a geometry object from the given TiXMLElement.
      * @param vertices this is the XML element representing the vertices of a
	  * geometry.
      * @return a geometry object, with the values of the provided element.
      */
    geometry * createGeometry(TiXmlElement* vertices);
	
	 /**
      * Creates a physicalProperties object from the given TiXMLElement.
      * @param setElement this is the XML element representing the physical
	  * properties.
      * @return a physicalProperties object, with the values of the provided
      * element.
      */
    physicalProperties *createPhysicalProperty(TiXmlElement *setElement);
	
	 /**
      * Creates an agentSet object from the given TiXMLElement.
      * @param set this is the XML element representing an agent set.
      * @return an agentSet object, with the values of the provided element.
      */
	agentSet *createAgentSet(TiXmlElement *set);
	
	 /**
      * Creates a paramSet object from the given TiXMLElement, with an empty
	  * name.
      * @param paramSetElement this is the XML element representing a collection
	  * of parameters.
      * @return a paramSet object, with the values of the provided element.
	  * @see createParamSet(TiXmlElement *parameSetElement, string name)
      */
    paramSet *createParamSet(TiXmlElement *paramSetElement);
	
	/**
      * Creates a paramSet object from the given TiXMLElement, with the provided
	  * name.
      * @param paramSetElement this is the XML element representing a collection
	  * of parameters.
	  * @param name the desired name of the paramSet as a string.
      * @return a agentSet object, with the values of the provided element.
      */
    paramSet *createParamSet(TiXmlElement *parameSetElement, string name);
	
	/**
      * Creates a createSingularity object from the given TiXMLElement.
      * @param singElement this is the XML element representing a singularity.
      * @return a singularity object, with the values of the provided element.
      */
    singularity *createSingularity(TiXmlElement *singElement);

public:
	/**
	  *Constructor 
	  */
	DomBuilder();
	
	/**
	  * Methods builds up the whole DOM structure and returns the top object of
	  * the DOM. This DOM is defined in Sa2dDom.h.
	  * @param filename the path of the configurationfile to be loaded.
	  * @return configurationfile reference to the top level object of the DOM.
	  */
	configurationfile* createDom(char* filename);
	
	/**
	  *Destructor
	  */
	virtual ~DomBuilder();

};


#endif /* DOMBUILDER_H_ */
